/*
 * @description:
 * @version: 1.0.1
 * @Author: xuqiulin
 * @Date: 2021-04-30 11:08:50
 * @LastEditors:
 * @LastEditTime: 2021-04-30 11:11:52
 */
package routers

import (
	"GameServer/ServerWeb/controllers"
	"net/http"

	"github.com/gin-gonic/gin"
	ginSwagger "github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"
)

func Router() *gin.Engine {
	r := gin.New()
	// router := r.Default()
	r.GET("/", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "hello world",
		})
	})

	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

	r.StaticFS("/files", http.Dir("files"))

	r.GET("/file", controllers.FileIndex)

	r.GET("/savedata/:pswd", controllers.SaveData)

	r.GET("/file/upload", controllers.UploadIndex)
	r.POST("/file/upload", controllers.Upload)

	conf := r.Group("/conf")
	{
		conf.GET("/refresh", controllers.RefreshConf)
		conf.POST("/upload", controllers.UploadConf)
		conf.GET("/data/:table", controllers.TableAllData)
		conf.GET("/data/:table/:key", controllers.TableSigleData)
	}
	users := r.Group("/user")
	{
		//users.GET("/name/:name", controllers.GetUserInfoByName)
		users.GET("/name/:name/lockBlocks", controllers.GetLockBlock)
		users.GET("/name/:name/hideShop", controllers.GetHideShop)
		users.GET("/uid/:uid", controllers.GetUserInfoByUid)
		users.GET("/list", controllers.GetUserList)
		users.POST("/modify", controllers.SetUserInfo)
		users.GET("/onlineNum", controllers.GetOnlineNum)
		users.GET("/closure", controllers.SetClosureTime)
		users.POST("/white", controllers.SetWhite)
	}
	userPet := r.Group("/userPet")
	{
		userPet.GET("/info/:uid", controllers.GetUserPetInfoByUid)
		userPet.GET("/list", controllers.GetUserPetList)
		userPet.POST("/modify", controllers.SetUserPetInfo)
	}

	userHero := r.Group("/userHero")
	{
		userHero.GET("/info/:uid", controllers.GetHerosByUid)
	}

	union := r.Group("/union")
	{
		union.GET("/list", controllers.UnionList)          //所有公会
		union.GET("/info/:unionId", controllers.UnionInfo) //公会信息
		union.GET("/members", controllers.UnionMemberList) //公会成员
	}

	system := r.Group("/system")
	{
		system.POST("/noticeMaintenance", controllers.NoticeMaintenance)
	}

	r.POST("/mail", controllers.SendMail)

	r.Use(gin.Logger())
	return r
}
